package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.activity.douluodalu.data.DouLuoDaLuUserData;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.DouLuoDaLuPb;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.douluodalu.CrossDouLouDaLuActivity;
import com.yanqu.road.server.manager.douluodalu.CrossDouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_DOU_LUO_DA_LU_UPLOAD_USER_DATA,desc = "上传用户变更信息")
public class CrossDouLuoDaLuUploadUserDataCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuUploadUserDataMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuUploadUserDataMsg.parseFrom(packet.getBytes());

        CrossDouLouDaLuActivity activity =CrossDouLuoDaLuMgr.getActivityOrNull(reqMsg.getActivityId(), groupId);
        if(activity != null){
            for (DouLuoDaLuProto.DouLuoDaLuUploadUserInfo userInfo : reqMsg.getUserInfoList()) {
                DouLuoDaLuUserData userData = activity.getAllUserMap().get(userInfo.getUserId());
                if(userData != null){
                    UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(userInfo.getPlayerInfo());
                    synchronized (userData) {
                        activity.updateUserData(userBaseInfo, userInfo.getAllPatronsEarn(), DouLuoDaLuPb.parseUserPatrons(userInfo.getAllPatronsList()), userData);
                    }
                }
            }
        }

    }

    @Override
    public void sendData() {

    }
}
